package com.example.homework3;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    private Button button;
    private Button button2;
    private Button button3;
    private Button button4;
    private Button button5;
    private Button button6;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        button2=(Button) findViewById(R.id.button2);
        button3=(Button) findViewById(R.id.button3);
        button4=(Button) findViewById(R.id.button4);
        button5=(Button) findViewById(R.id.button5);
        button6=(Button) findViewById(R.id.button6);

        button2.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SimpleDialogFragment dialog=new SimpleDialogFragment();
                dialog.show(getSupportFragmentManager(),"simple");
            }
        });
        button3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ChoiceDialogFragment dialog=new ChoiceDialogFragment();
                dialog.setListener(new ChoiceDialogFragment.NotifyDialogListener() {
                    @Override
                    public void onDialogPositiveClicked(String gender) {
                        Toast.makeText(getApplicationContext(),"你选择了："+gender,Toast.LENGTH_SHORT).show();
                    }
                });
                dialog.show(getSupportFragmentManager(),"choice");
            }
        });
        button4.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               SingleChoiceDialogFragment dialog=new SingleChoiceDialogFragment();
               dialog.show(getSupportFragmentManager(),"single");
            }
        });
        button5.setOnClickListener(new View.OnClickListener()
        {
            public void onClick(View view){
                MultiChoiceDialogFragment dialog=new MultiChoiceDialogFragment();
                dialog.show(getSupportFragmentManager(),"multi");
            }
        });
    }
    public void onOldButtonClicked(View view){
        AlertDialog dialog;
        dialog=new AlertDialog.Builder(this).setTitle("旧版对话框")
                .setMessage("这是旧版的对话框，使用简单\n但是没有自动支持屏幕翻转！")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getApplicationContext(),"你确定了！",Toast.LENGTH_SHORT).show();
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getApplicationContext(),"你取消了！",Toast.LENGTH_SHORT).show();
                    }
                })
                .create();
        dialog.show();
    }
}
